package logic

import (
	"context"
	"shuqi-novel/models"

	"shuqi-novel/novelrpc/internal/svc"
	"shuqi-novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ArticleAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewArticleAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleAddLogic {
	return &ArticleAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 小说添加
func (l *ArticleAddLogic) ArticleAdd(in *novelrpc.ArticleAddRequest) (*novelrpc.ArticleAddResponse, error) {
	// todo: add your logic here and delete this line

	article := models.Article{
		Name:   in.Name,
		Author: in.Author,
		Price:  float64(in.Price),
	}

	if err := article.ArticleAdd(models.DB); err != nil {
		return nil, err
	}

	return &novelrpc.ArticleAddResponse{
		ArticleId: int64(article.ID),
	}, nil
}
